'''
Created on Feb 5, 2013

@author: loic
'''
from mp3db import mp3sqldb
from optparse import OptionParser

def main():
    parser = OptionParser()
    parser.add_option("-c", "--command", dest="command",
                  help="command (add, update, list, create, scan_folder, scan_folder_curses)", action="store", type='choice', choices=('add', 'update', 'list', 'create', 'scan_folder'), default='list')
    parser.add_option("-C", "--curses", dest="curses", help="uses curses", action="store_true")
    (options, args) = parser.parse_args()
    
    db=mp3sqldb('/home/loic/Documents/mp3.sqlite')
    if options.command == 'list':
        fields = None
        for r in db.search():
            if not fields:
                fields = r.keys()
            for f in fields:
                print f,': ', r[f], ' ',
            print
    elif options.command == 'create':
        db.create_db()
        db.close()
    elif options.command == 'scan_folder':
        if len(args) < 1:
            print 'missing folder to scan'
            return
        if options.curses: 
            from mp3scan import mp3scanCurses as mp3scan
        else:
            from mp3scan import mp3scan
        scanner = mp3scan(db)
        scanner.scan_folder(args[0])
    pass

if __name__ == '__main__':
    main()